package servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CountServlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer name1=Integer.parseInt(req.getParameter("name1"));
        Integer name2=Integer.parseInt(req.getParameter("name2"));
        String sf=req.getParameter("sf");

        String ysf=null;
        Integer  count=0;
        if (sf.equals("1")){
            count=name1+name2;
            ysf="+";
        }
        if (sf.equals("2")){
            count=name1-name2;
            ysf="-";

        }
        if (sf.equals("3")){
            count=name1*name2;
            ysf="*";

        }
        if (sf.equals("4")){
            count=name1/name2;
            ysf="/";

        }
        req.setAttribute("name1",name1);
        req.setAttribute("name2",name2);
        req.setAttribute("count1",count);
        req.setAttribute("ysf",ysf);
        req.getRequestDispatcher("calculator-page-02.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
